import { CopyControllerBase } from "../view/copy/controller/CopyControllerBase";
import { UpgradeCrossSecretSkillPanel } from "../view/copy/upgradeCrossSecret/UpgradeCrossSecretSkillPanel";
import { CrossAryadevaSecretCopyInfoView } from "../view/copy/crossAryadevaSecretCopy/CrossAryadevaSecretCopyInfoView";
import { CopyType } from "../view/copy/CopyType";
import { SelectCopyDropTimeView } from "../view/copy/crossAryadevaSecretCopy/SelectCopyDropTimeView";
import { Language } from "../../../extend/language/Language";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SSeqPlayerItem } from "../../../Message/Public/SSeqPlayerItem";
import { SCrossSecretBossList } from "../../../Message/Public/SCrossSecretBossList";
import { GameDefConfig } from "../resource/GameDefConfig";
import { SCrossSecretCopyInfo } from "../../../Message/Public/SCrossSecretCopyInfo";
import { ClockManager } from "../manager/ClockManager";
import { SCrossSecretSkillInfoToClient } from "../../../Message/Public/SCrossSecretSkillInfoToClient";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { TCopy } from "../../../Message/Db/Tables/TCopy";
type int = number;
//class UpgradeCrossSecretCopyController
    
    export  class UpgradeCrossSecretCopyController extends CopyControllerBase
    {
        constructor()
        {
            
            super();this._crossSecretRewardItems = [];
            return;
        }

        public get crossSecretRewardItemsNum(): int
        {
            return this._crossSecretRewardItems.length;
        }

        public get skillPanel(): UpgradeCrossSecretSkillPanel
        {
            if (this._skillPanel == null) 
            {
                this._skillPanel = new UpgradeCrossSecretSkillPanel();
            }
            return this._skillPanel;
        }

        public get copyInfoView(): CrossAryadevaSecretCopyInfoView
        {
            if (this._copyInfoView == null) 
            {
                this._copyInfoView = new CrossAryadevaSecretCopyInfoView();
                this._copyInfoView.copyType = CopyType.UPGRARE_CROSS_SECRET_COPY;
            }
            return this._copyInfoView;
        }

        public get dropTimes(): SelectCopyDropTimeView
        {
            if (this._dropTimes == null) 
            {
                this._dropTimes = new SelectCopyDropTimeView();
                this._dropTimes.title = Language.getString(27614);
            }
            return this._dropTimes;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicUpgradeCrossSecretRewardItems, this.onUpgradeCrossSecretRewardItemsHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicUpgradeCrossSecretItemList, this.onUpgradeCrossSecretItemListHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicUpgradeCrossSecretBossList, this.onUpgradeCrossSecretBossListHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicUpgradeCrossSecretCopyInfo, this.onUpgradeCrossSecretCopyInfoHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicUpgradeCrossSecretSkillInfo, this.onUpgradeCrossSecretSkillInfoHandler);
            return;
        }

        protected /* override */ addListener(): void
        {
            Dispatcher.addEventListener(EventName.UpgradeCrossSecretUseSkill, this.onUpgradeCrossSecretUseSkillHandler);
            Dispatcher.addEventListener(EventName.GetCopyMultiplicityReward, this.onUpgradeCrossSecretGetItemsHandler);
            Dispatcher.addEventListener(EventName.UpgradeCrossSecretLeaveAndShowRewardView, this.onCopyLeaveAndShowRewardView);
            return;
        }

        protected /* override */ removeListener(): void
        {
            Dispatcher.removeEventListener(EventName.UpgradeCrossSecretUseSkill, this.onUpgradeCrossSecretUseSkillHandler);
            Dispatcher.removeEventListener(EventName.GetCopyMultiplicityReward, this.onUpgradeCrossSecretGetItemsHandler);
            Dispatcher.removeEventListener(EventName.UpgradeCrossSecretLeaveAndShowRewardView, this.onCopyLeaveAndShowRewardView);
            return;
        }

        /* internal  */onUpgradeCrossSecretRewardItemsHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSeqPlayerItem;
            this._crossSecretRewardItems = loc1.playerItem;
            this.copyInfoView.updataAwardInfo(this._crossSecretRewardItems);
            return;
        }

        /* internal  */onUpgradeCrossSecretItemListHandler(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc1=arg1.messageBase as SSeqPlayerItem;
            if (loc1) 
            {
                loc2 = [];
                loc3 = loc1.playerItem;
                loc5 = 0;
                while (loc5 < loc3.length) 
                {
                    if ((loc4 = loc3[loc5]) != null) 
                    {
                        loc6 = 0;
                        while (loc6 < loc4.itemAmount) 
                        {
                            loc2.push(loc4);
                            ++loc6;
                        }
                    }
                    ++loc5;
                }
                this.skillPanel.updateSkillProps(loc2);
            }
            return;
        }

        /* internal  */onUpgradeCrossSecretBossListHandler(arg1: MessageBlock): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            var loc1=arg1.messageBase as SCrossSecretBossList;
            if (arg1 && loc1.bossInfo) 
            {
                loc2 = loc1.bossInfo[2190006] > 0 ? 1 : 0;
                loc3 = loc1.bossInfo[2190007] > 0 ? 1 : 0;
                loc4 = loc1.bossInfo[2190008] > 0 ? 1 : 0;
                loc5 = loc1.bossInfo[2190009] > 0 ? 1 : 0;
                loc6 = loc1.bossInfo[2190010] > 0 ? 1 : 0;
                loc7 = Language.getStringByParam(27613, loc2, loc3, loc4, loc5, loc6);
                this.copyInfoView.updataKillBossInfo(loc7);
                if (loc2 + loc3 + loc4 + loc5 + loc6 >= 5) 
                {
                    this.copyInfoView.stopLeftTime();
                }
                if (loc2 + loc3 + loc4 + loc5 + loc6 >= 5 && this._crossSecretRewardItems.length > 0) 
                {
                    this.rewardViewShow(this._crossSecretRewardItems);
                }
            }
            return;
        }

        /* internal  */rewardViewShow(arg1: Array<any>, arg2: Boolean=false): void
        {
            this.dropTimes.itemData(arg1);
            this.dropTimes.multipleOptions = GameDefConfig.instance.getCopyDropTime(3);
            this.dropTimes.showReturnBtn(arg2);
            this.dropTimes.show();
            return;
        }

        /* internal  */onUpgradeCrossSecretCopyInfoHandler(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc1=arg1.messageBase as SCrossSecretCopyInfo;
            if (loc1 && loc1.endDt) 
            {
                loc2 = ClockManager.instance.nowDate;
                this.copyInfoView.updateLeftTime(int((loc1.endDt.time - loc2.time) / 1000));
            }
            return;
        }

        /* internal  */onUpgradeCrossSecretSkillInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCrossSecretSkillInfoToClient;
            if (this.skillPanel) 
            {
                this.skillPanel.updateSkillCd(loc1.vCrossSecretSkillInfo);
            }
            return;
        }

        /* internal  */onUpgradeCrossSecretUseSkillHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            var loc2=loc1.itemCode as int;
            var loc3=loc1.entityIds as Array<any>;
            var loc4=loc1.point;
            GameProxy.copy.useItemInUpgradeCrossSecret(true, loc2, loc3, loc4);
            return;
        }

        /* internal  */onUpgradeCrossSecretGetItemsHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["times"] as int;
            GameProxy.copy.getUpgradeCrossSecretItem(loc1);
            return;
        }

        /* internal  */onCopyLeaveAndShowRewardView(arg1: DataEvent): void
        {
            var loc1=arg1.data.showReturnBtn;
            this.rewardViewShow(this._crossSecretRewardItems, loc1);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            this.skillPanel.show();
            this.copyInfoView.show();
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            this.skillPanel.hide();
            this.copyInfoView.hide();
            this.dropTimes.hide();
            return;
        }

        public /* override */ stageResize(): void
        {
            return;
        }

        private /* var */_skillPanel: UpgradeCrossSecretSkillPanel;

        private /* var */_copyInfoView: CrossAryadevaSecretCopyInfoView;

        private /* var */_dropTimes: SelectCopyDropTimeView;

        private /* var */_crossSecretRewardItems: Array<any>;
    }
